#include <iostream>
#include <mutex>
#include <memory>

std::mutex mutex_;

class Singleton {
private:
    int data_;
private:
    Singleton() :data_(10) { std::cout << "单例 饿汉模式!\n"; }
    Singleton(const Singleton &) = delete;
public:
    static Singleton& get_instance() {
        static Singleton singleton_;
        return singleton_;
    }
    int get_data() { return data_; }
};

class Singleton1 {
private:
    int data_;
    //static Singleton1 *singleton_;
    static std::unique_ptr<Singleton1> singleton_;
private:
    Singleton1() :data_(10) { std::cout << "单例 饿汉模式!\n"; }
    Singleton1(const Singleton &) = delete;
public:
    static Singleton1& get_instance() {
        if (singleton_ == nullptr) {
            std::lock_guard<std::mutex> lock(mutex_);
            if (singleton_ == nullptr) {
                singleton_.reset(new Singleton1);
            }
        }
        return *singleton_;
    }
    int get_data() { return data_; }
};
std::unique_ptr<Singleton1> Singleton1::singleton_ = nullptr;

int main() {
    Singleton1::get_instance().get_data();
    return 0;
}
